package com.hj.file.util;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import javax.imageio.IIOImage;
import java.io.File;

public class TesseractUtil {

    public String tesseractContent() {
        ITesseract instance = new Tesseract();
        File file = new File("D:\\testWord\\image\\outt2.jpg");
        File resources = new File(this.getClass().getResource("/").getPath());
        instance.setDatapath(resources.getParentFile() + File.separator + "classes" + File.separator + "tessdata");
        instance.setLanguage("chi_sim");
        String content = "";
        try {
            String codeString = instance.doOCR(file);
            content = codeString;
            System.out.println("识别:" + codeString);
        } catch (TesseractException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return content;
    }
}
